<?php

namespace app\topics\middle;

class DetailCreateMiddle extends \app\base\middle\BaseMiddle {


    protected function meta() {
        $this->setMeta('发布讨论');
        $this->setName('发布讨论');
        $this->setCrumb([
            [
                'name' => '发布讨论',
                'url' => url()
            ]
        ]);

        return $this->run([
            'pageInfo' => $this->pageInfo
        ]);
    }

    protected function data() {
        $where = [
            'type' => 'common'
        ];
        $nodeList = target('topics/TopicsNode')->nodeList($where);
        return $this->run([
            'nodeList' => $nodeList
        ]);
    }

    protected function post() {
        $data = $this->params['data'];
        $data['user_id'] = $this->params['user_id'];
        $id = target('topics/TopicsDetailCommon')->saveData('add', $data);
        if (!$id) {
            return $this->stop(target('topics/TopicsDetailCommon')->getError());
        }
        return $this->run([
            'id' => $id
        ], '发表主题成功！');
    }


}